package com.hanserwei.community.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    private final JWTInterceptor jwtInterceptor;

    // 依赖注入 JWTInterceptor
    public WebMvcConfig(JWTInterceptor jwtInterceptor) {
        this.jwtInterceptor = jwtInterceptor;
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 注册你的拦截器
        registry.addInterceptor(jwtInterceptor)
                // 拦截所有请求，下面针对无需登录的接口放行
                .addPathPatterns("/**")
                // 登录、注册与验证码接口无需鉴权
                .excludePathPatterns(
                        "/user/login",
                        "/user/register",
                        "/user/createCaptcha",
                        "/error",
                        "/swagger-ui.html",
                        "/swagger-ui/**",
                        "/v3/api-docs/**");
    }
}
